<template>
	<view>
		<view class="uploadfont">
			上传挂号单和票据
		</view>
		<view class="ptoto">
			<image v-if="Img1==''" @tap="ticketphoto" src="https://xb-street.oss-cn-shanghai.aliyuncs.com/xb-doctor-manage/static/images/cailiao@2x.png" mode=""></image>
			<image v-if="Img1!==''" :src="Img1" mode="" @tap="ticketphoto"></image>
		</view>
		<view class="ptoto mt-2">
			<image @tap="ticketphoto1" v-if="Img2==''" src="https://xb-street.oss-cn-shanghai.aliyuncs.com/xb-doctor-manage/static/images/cailiao@2x.png" mode=""></image>
			<image @tap="ticketphoto1" v-if="Img2!==''" :src="Img2" mode=""></image>
		</view>
		<view class="btn" @tap="promise">
			提交
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Img1:'',
				Img2:'',
				longitude:'',
				latitude:'',  
				receiveNo:'', //接单编号
				orderNo:'', //订单编号,
				data:[], //就医材料
			}
		},
		onLoad(option) {
			this.orderNo = option.orderNo
			this.receiveNo = option.accompanyReceiveNo
			this.getlocation()
		},
		methods: {
			getlocation(){
				let _this = this
				uni.getLocation({
				    type: 'gcj02',
				    success:  function(res) {
				        console.log('当前位置的经度：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						_this.longitude = res.longitude
						_this.latitude = res.latitude
				    }
				});
			},
			ticketphoto() {
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //相册、拍摄两者都有
					success: (res)=> {
						console.log(JSON.stringify(res.tempFilePaths[0]));
						// this.Img1 = res.tempFilePaths[0]
						uni.uploadFile({
							url: "https://app.xiangban365.com/app_mobile/" + "upload/file", //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							header: {
								ContentType: "image/jpg"
							},
							formData: {
								'user': 'test'
							},
							success:(uploadFileRes)=> {
								let data = JSON.parse(uploadFileRes.data)		
								this.Img1 = data.dataMap
								this.data.push(this.Img1)
							}
						});
						
						}
					});
			},
			ticketphoto1() {
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album','camera'], //相册、拍摄两者都有
					success: (res)=> {
						console.log(JSON.stringify(res.tempFilePaths[0]));
						// this.Img2 = res.tempFilePaths[0]
						uni.uploadFile({
							url: "https://app.xiangban365.com/app_mobile/" + "upload/file", //仅为示例，非真实的接口地址
							filePath: res.tempFilePaths[0],
							name: 'file',
							header: {
								ContentType: "image/jpg"
							},
							formData: {
								'user': 'test'
							},
							success:(uploadFileRes)=> {
								let data = JSON.parse(uploadFileRes.data)		
								this.Img2 = data.dataMap
								this.data.push(this.Img2)
							}
						});
						
						}
					});
			},
			promise(){
				if(this.data.length<=1){
					uni.showToast({
						title: '票据和材料不能为空',
						duration: 1000,
						icon: "none"
					});
					return
				}
				console.log(this.data)
				this.$api.submitdata({
					orderNo:this.orderNo,
					receiveNo:this.receiveNo,
					longitude:this.longitude,
					latitude:this.latitude,
					data:JSON.stringify(this.data)
				}).then((res) => {
					console.log(res)
					if(res.data.success){
						// console.log(res.data.dataMap)
						uni.showToast({
							title:'上传成功',
							icon:'none'
						})
						uni.$emit('trigger',1)
						uni.navigateBack({
							delta:1
						})
					}else{
						uni.showToast({
							title:res.data.message,
							icon:'none'
						})
					}
					
							
				})
			},
		}
	}
</script>

<style lang="less" scoped>
.uploadfont{
	width: 690rpx;
	height: 100rpx;
	padding: 0 30rpx;
	line-height: 100rpx;
	font-size: 32rpx;
	font-weight: bold;
	color: #333333;
}
.ptoto{
	text-align: center;
	image{
		width: 600rpx;
		height: 400rpx;
	}
}
.btn{
	width: 600rpx;
	height: 100rpx;
	font-size: 32rpx;
	background-color: #4CA6FF;
	border-radius: 50rpx;
	line-height: 100rpx;
	text-align: center;
	color: #FFFFFF;
	margin: 0 auto;
	position: absolute;
	bottom: 100rpx;
	left: 75rpx;
}
</style>
